package com.freesky.picuplodmachine;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;

/**
 * @author: 陈玉林
 * @modifiedBy:
 * @date: Create In 10:28 2018/12/27
 * @description:
 */
@RestController
public class UploadController {
    @Value("${user.head-portrait.width}")
    private int headPortraitWidth;
    @Value("${user.head-portrait.height}")
    private int headPortraitHeight;
    @PostMapping("/upload")
    public String upload(@RequestPart(value = "file") MultipartFile file, @RequestParam(value = "degree") int degree) throws Exception {
        String suffix = "jpg";
        File newFile = new File("d:/pic/out/new.jpg");
        file.transferTo(newFile);
        //图片裁剪
        newFile = ImgUtil.zoom(headPortraitWidth, headPortraitHeight, newFile, suffix);
        ImgUtil.spin(degree,newFile,suffix);
        return "success";
    }
}
